package com.ujson.uaa.types;

import com.ujson.uaa.persistence.UserDo;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

/**
 * <h3>ujson-parent</h3>
 * <p>UserDo转User转换器</p>
 *
 * @author JerryLiu  a1031757312@gmail.com
 * @version 1.0
 * @date 2021-11-20 15:23
 */
@Mapper
public interface UserMapper {

    UserMapper INSTANCE = Mappers.getMapper(UserMapper.class);

    @Mappings({
            @Mapping(target = "username", source = "name"),
            @Mapping(target = "userId.id", source = "id")
    })
    User convert(UserDo userDo);

    @Mappings({
            @Mapping(target = "id", source = "userId.id"),
            @Mapping(target = "name", source = "username")
    })
    UserDo convert(User user);

}
